﻿using System;
using System.Linq;
using System.Windows.Forms;
using NBi.UI.Genbi.Interface.TestSuiteGenerator.Events;
using NBi.UI.Genbi.Presenter;

namespace NBi.UI.Genbi.Command.TestCases
{
	class OpenTestCasesCommand: CommandBase
	{
		protected readonly TestCasesPresenter presenter;


		public OpenTestCasesCommand(TestCasesPresenter presenter)
		{
			this.presenter = presenter;
		}

		/// <summary>
		/// Refreshes the command state.
		/// </summary>
		public override void Refresh()
		{
			this.IsEnabled = true;
		}

		/// <summary>
		/// Executes the command logics.
		/// </summary>
		public override void Invoke()
		{
			var openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = "All Files (*.*)|*.*|CSV (Comma delimited) (*.csv)|*.csv|Text Files (*.txt)|*.txt";
			openFileDialog.FilterIndex = 2;
			DialogResult result = openFileDialog.ShowDialog();
			if (result == DialogResult.OK)
				presenter.LoadCsv(openFileDialog.FileName);            
		}

	}
}
